//
//  CoreTextViewController.m
//  Ricky_RefreshControl
//
//  Created by MR-zhang on 15/7/9.
//  Copyright (c) 2015年 Ricky. All rights reserved.
//

#import "CoreTextViewController.h"
#import "UIScrollView+RCKRefreshControl.h"
#import "RickyRefreshView.h"

@interface CoreTextViewController ()
{
    UIScrollView *_scrollView;
}
@end

@implementation CoreTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"PullTextRefresh";
    
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.backgroundColor = [UIColor colorWithWhite:0.97 alpha:1.0];
    _scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, MAX(_scrollView.contentSize.height, _scrollView.frame.size.height+1));
    [self.view addSubview:_scrollView];
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 60)];
    contentLabel.textAlignment = 1;
    contentLabel.numberOfLines = 0;
    contentLabel.text = @"试试下拉，上拉";
    contentLabel.backgroundColor = [UIColor clearColor];
    [_scrollView addSubview:contentLabel];
    
    __weak __typeof(self)weakSelf = self;
    // 添加顶部刷新控件
    [_scrollView addPullTextRickyRefreshHeaderViewWithPullText:nil pullTextColor:[UIColor orangeColor] pullTextFont:nil refreshingText:nil refreshingTextColor:[UIColor orangeColor] refreshingTextFont:nil withCallBackAction:^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf handleRefreshHeader];
    }];
    
    // 添加底部加载控件
    [_scrollView addPullTextRickyRefreshFooterViewWithPullText:nil pullTextColor:[UIColor orangeColor] pullTextFont:nil refreshingText:nil refreshingTextColor:[UIColor orangeColor] refreshingTextFont:nil withCallBackAction:^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf handleRefreshFooter];
    }];
}

- (void)handleRefreshHeader {
    [self performSelector:@selector(completeHeader) withObject:nil afterDelay:6.0];
}

- (void)handleRefreshFooter
{
    [self performSelector:@selector(completeFooter) withObject:nil afterDelay:2.0];
}

- (void)completeHeader
{
    [_scrollView completeRickyRefreshHeaderWithCompleteType:RickyRefreshCompleteTypeError];
}

- (void)completeFooter
{
    [_scrollView completeRickyRefreshFooterWithCompleteType:RickyRefreshCompleteTypeError];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
